//
//  DYCommonDCell.m
//  PrivatePhoto
//
//  Created by PrivatePhoto Team on 2021.
//  Copyright © 2021年 PrivatePhoto Team. All rights reserved.
//

#import "DYCommonDCell.h"
@interface DYCommonDCell()
@property (nonatomic, strong) UIView *containerView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *detailLabel;
@property (nonatomic, strong) UILabel *numberLabel;
@property (nonatomic, strong) UIImageView *accImg;

@end

@implementation DYCommonDCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.contentView.backgroundColor = [UIColor colorWithHexString:@"#EDF4FF"];
        [self configSubView];
    }
    return self;
}

-(void)setFrame:(CGRect)frame
{
    frame.origin.x = 10;//这里间距为10，可以根据自己的情况调整
    frame.size.width -= 2 * frame.origin.x;
    frame.size.height -= 2 * 5;
    [super setFrame:frame];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.layer.masksToBounds = YES;
    self.layer.cornerRadius = 12.0;
    [self.accImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_offset(-5);
        make.centerY.mas_offset(0);
    }];
    [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.accImg.mas_left).mas_offset(-10);
        make.centerY.mas_offset(0);
    }];
    
    [self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.numberLabel.mas_left);
        make.top.bottom.left.mas_offset(0);
    }];
    if (self.detailLabel.hidden) {
        [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.containerView.mas_left).mas_offset(10);
            make.centerY.mas_offset(0);
        }];
    }else{
        [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.containerView.mas_left).mas_offset(10);
            make.top.mas_offset(8);
        }];
        [self.detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.containerView.mas_left).mas_offset(10);
            make.top.mas_equalTo(self.nameLabel.mas_bottom).mas_offset(8);
        }];
  
    }
}

- (void)configSubView{

   
    [self.contentView addSubview:self.accImg];
    [self.contentView addSubview:self.numberLabel];
    [self.contentView addSubview:self.containerView];
    [self.containerView addSubview:self.nameLabel];
    [self.containerView addSubview:self.detailLabel];
   
 
}

- (void)btnDidClick:(UIButton *)sender{
    sender.selected = !sender.selected;
}

#pragma mark --setter/getter

- (void)setCellModel:(wBaseModel *)cellModel{
    _cellModel = cellModel;
    self.nameLabel.text = cellModel.labelName;
    if (!cellModel.detailTip.length) {
        self.detailLabel.hidden = YES;
    }else{
        self.detailLabel.hidden = NO;
        self.detailLabel.text = cellModel.detailTip;
    }
    self.numberLabel.text = @(cellModel.rightCount).stringValue;
    [self layoutIfNeeded];
    [self setNeedsLayout];
}

- (UIView *)containerView{
    if (!_containerView) {
        _containerView = [[UIView alloc] init];
    }
    return _containerView;
}

- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.font = [UIFont systemFontOfSize:16 weight:3];
        _nameLabel.textColor = [UIColor colorWithHexString:@"#323232"];
        _nameLabel.text = @"屏幕截图";
    }
    return _nameLabel;
}

- (UILabel *)detailLabel{
    if (!_detailLabel) {
        _detailLabel = [[UILabel alloc] init];
        _detailLabel.font = [UIFont systemFontOfSize:14];
        _detailLabel.textColor = [UIColor colorWithHexString:@"#323232"];
        _detailLabel.text = @"430张照片  677.2MB";
    }
    return _detailLabel;
}
    
- (UILabel *)numberLabel{
    if (!_numberLabel) {
        _numberLabel = [[UILabel alloc] init];
        _numberLabel.font = [UIFont systemFontOfSize:14];
        _numberLabel.textColor = [UIColor colorWithHexString:@"#323232"];
        _numberLabel.text = @"26";
    }
    return _numberLabel;
}

- (UIImageView *)accImg{
    if (!_accImg) {
        _accImg = [[UIImageView alloc] init];
        _accImg.image = [UIImage imageNamed:@"jt"];
    }
    return _accImg;
}

@end
